home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / clsres1a / clsresiz.cls next >
Text File  |  1999-09-04  |  16KB  |  309 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "clsResize"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. ' ======================================================================================== '
  11. ' Component : clsResize                                               Created : 01/05/1999 '
  12. ' File Name : clsResize.cls                                           Author  : A D Moss   '
  13. '                                                                                          '
  14. ' Purpose   : Resize and Reposition all controls on a Form.                                '
  15. ' ======================================================================================== '
  16. '                 Copyright ⌐ 1999 - Adam David Moss - All Rights Reserved                 '
  17. '                                                                                          '
  18. ' ======================================================================================== '
  19. '                                                                                          '
  20. Option Explicit
  21. ' ======================================================================================== '
  22. ' API Declarations.                                                                        '
  23. ' ======================================================================================== '
  24. Private Declare Function LockWindowUpdate Lib "user32.dll" (ByVal hwndLock As Long) As Long
  25.  
  26. ' ======================================================================================== '
  27. ' Constant Declarations.                                                                   '
  28. ' ======================================================================================== '
  29. Private Const SSTAB_DIALOG_OFFSET As Long = 75000
  30. Private Const SSTAB_TYPE_NAME As String = "SSTAB"
  31.  
  32. Private Const ResizeRepositionCommand As String = "@"
  33. Private Const ResizeRepositionLeft As String = "L"
  34. Private Const ResizeRepositionTop As String = "T"
  35. Private Const ResizeRepositionWidth As String = "W"
  36. Private Const ResizeRepositionHeight As String = "H"
  37.  
  38. ' ======================================================================================== '
  39. ' Type Declarations.                                                                       '
  40. ' ======================================================================================== '
  41. Private Type ControlPosition
  42.   ControlInstance As Control                         'Reference to the control instance.
  43.   OriginalLeft As Long                               'Original Left position of the Control.
  44.   OriginalTop As Long                                'Original Top position of the Control.
  45.   OriginalWidth As Long                              'Original Width of the Control.
  46.   OriginalHeight As Long                             'Original Height of the Control.
  47. End Type
  48.  
  49. ' ======================================================================================== '
  50. ' Enumeration Declarations.                                                                '
  51. ' ======================================================================================== '
  52.  
  53. ' ======================================================================================== '
  54. ' Event Declarations.                                                                      '
  55. ' ======================================================================================== '
  56.  
  57. ' ======================================================================================== '
  58. ' Public Variable Declarations.                                                            '
  59. ' ======================================================================================== '
  60.  
  61. ' ======================================================================================== '
  62. ' Private Variable Declarations.                                                           '
  63. ' ======================================================================================== '
  64. Private m_SourceForm As Form                         'The form to be resized.
  65. Private m_FormWidth As Long                          'Original form width.
  66. Private m_FormHeight As Long                         'Original form height.
  67. Private m_Controls() As ControlPosition              'Array for storing control information.
  68. Private m_IsFirstResize As Boolean                   'Flag indicating first resize.
  69.  
  70. ' ======================================================================================== '
  71. ' Routine     : Class_Initialize                                      Created : 01/05/1999 '
  72. ' Scope       : Private                                               Author  : A D Moss   '
  73. ' Description : Constructor used when an instance of this class is created.                '
  74. ' ======================================================================================== '
  75. Private Sub Class_Initialize()
  76.   Set m_SourceForm = Nothing
  77.  
  78.   m_IsFirstResize = True
  79. End Sub
  80.  
  81. ' ======================================================================================== '
  82. ' Routine     : Class_Terminate                                       Created : 01/05/1999 '
  83. ' Scope       : Private                                               Author  : A D Moss   '
  84. ' Description : Destructor used when an instance of this class is destroyed.               '
  85. ' ======================================================================================== '
  86. Private Sub Class_Terminate()
  87.   Erase m_Controls
  88.  
  89.   Set m_SourceForm = Nothing
  90. End Sub
  91.  
  92. ' ======================================================================================== '
  93. ' Routine     : SourceForm (Get)                                      Created : 01/05/1999 '
  94. ' Scope       : Public                                                Author  : A D Moss   '
  95. ' Description : Return the Form currently being used by an instance of this class.         '
  96. ' ======================================================================================== '
  97. Public Property Get SourceForm() As Form
  98.   Set SourceForm = m_SourceForm
  99. End Property
  100.  
  101. ' ======================================================================================== '
  102. ' Routine     : SourceForm (Let)                                      Created : 01/05/1999 '
  103. ' Scope       : Public                                                Author  : A D Moss   '
  104. ' Description : Set the Form to be used by an instance of this class.                      '
  105. ' ======================================================================================== '
  106. Public Property Let SourceForm(New_SourceForm As Form)
  107.   Set m_SourceForm = New_SourceForm
  108. End Property
  109.  
  110. ' ======================================================================================== '
  111. ' Routine     : SizeFormToScreen                                      Created : 01/05/1999 '
  112. ' Scope       : Public                                                Author  : A D Moss   '
  113. ' Description : Size the Form to n Percent of the Screen.                                  '
  114. ' ======================================================================================== '
  115. Public Sub SizeFormToScreen(Optional Percent As Byte = 100)
  116.   'Variable Declarations.
  117.   Dim FormHeight As Long, FormWidth As Long
  118.  
  119.   'Check if the form has not been resized before.
  120.   If m_IsFirstResize Then
  121.     Call SaveInitialStates
  122.   End If
  123.  
  124.   'Calculate the new height and width the form needs to be resized to, based on the current
  125.   'screen resolution.
  126.   FormHeight = Int(Screen.Height * (Percent / 100))
  127.   FormWidth = Int(Screen.Width * (Percent / 100))
  128.  
  129.   'Use the Form that is to be resized.
  130.   With m_SourceForm
  131.     'Change the demensions and position of the form.
  132.     .Top = (Screen.Height - FormHeight) / 2
  133.     .Left = (Screen.Width - FormWidth) / 2
  134.     .Height = FormHeight
  135.     .Width = FormWidth
  136.   End With
  137.  
  138.   'Resize all of the controls on the form.
  139.   Call ResizeControls
  140. End Sub
  141.  
  142. ' ======================================================================================== '
  143. '